package com.shaoshaohuo.app.adapter;

import java.util.List;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.entity.ExchangeRecord;
import com.shaoshaohuo.app.utils.ImageLoadUtil;
import com.shaoshaohuo.app.utils.StringHelper;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class ExchangeRecordAdapter<T> extends MyBaseAdapter<ExchangeRecord> {

	public ExchangeRecordAdapter(Context ctx, List<ExchangeRecord> list, boolean flag) {
		super(ctx, list, flag);
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup group) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, R.layout.view_exchange_record_item, null);
			holder = new ViewHolder();
			holder.imageView = (ImageView) convertView.findViewById(R.id.imageview_image);
			holder.titleText = (TextView) convertView.findViewById(R.id.textview_title);
			holder.pointText = (TextView) convertView.findViewById(R.id.textview_point);
			holder.mTimeText = (TextView) convertView.findViewById(R.id.textview_time);
			holder.mStatusText = (TextView) convertView.findViewById(R.id.textview_status);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		ExchangeRecord msg = list.get(pos);
		
		holder.titleText.setText(msg.getGoodsinfo().getTitle());
		holder.pointText.setText(msg.getIntegral() + "积分");
		holder.mTimeText.setText("时间:"+StringHelper.formatDateDay(msg.getCursor()));
		switch (msg.getStatus()) {
		case "3":
			holder.mStatusText.setText("待发货");
			break;
		case "4":
			holder.mStatusText.setText("已发货");
			break;
		case "5":
			holder.mStatusText.setText("已签收");
			break;
		}
//
//		LoadUtils.getInstance().loadImage(holder.imageView, msg.getGoodsinfo().getImg());
		ImageLoader.getInstance().displayImage(msg.getGoodsinfo().getImg(), holder.imageView,ImageLoadUtil.build);
		return convertView;
	}

	static class ViewHolder {
		ImageView imageView;
		TextView titleText;
		TextView pointText;
		TextView mTimeText;
		TextView mStatusText;
	}

}
